from django.db import models
from django.db.models import PROTECT, CASCADE

from apps.users.models import User


class UserBaseInfo(models.Model):
    real_name = models.CharField(max_length=11, verbose_name='真实姓名')
    cur_status = models.CharField(max_length=20, verbose_name='工作状态')
    education = models.CharField(max_length=10, verbose_name='学历')
    eduage = models.CharField(max_length=6, verbose_name='学龄')
    b_mobile = models.CharField(max_length=15, null=True, verbose_name='联系手机')
    b_email = models.CharField(max_length=20, null=True, verbose_name='联系邮箱')
    gender = models.CharField(max_length=10, verbose_name='性别')
    head_image = models.CharField(max_length=100, verbose_name='头像')
    user = models.ForeignKey(User, on_delete=PROTECT, verbose_name='用户id')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_user_basic_info'
        verbose_name = '用户基本信息表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.real_name


class ExpectWork(models.Model):
    city = models.CharField(max_length=12, verbose_name='城市')
    work_kind = models.CharField(max_length=6, verbose_name='职别')
    position = models.CharField(max_length=20, verbose_name='职位')
    salary = models.CharField(max_length=10, verbose_name='薪水')
    user = models.ForeignKey(User, on_delete=PROTECT, verbose_name='用户id')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_user_expect_work'
        verbose_name = '用户期望工作表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.position


class WorkExp(models.Model):
    """工作经历"""

    company_name = models.CharField(max_length=20, verbose_name='公司名称')
    job_name = models.CharField(max_length=16, verbose_name='职位名称')
    start_time = models.CharField(max_length=16, verbose_name='工作起始时间')
    end_time = models.CharField(max_length=16, verbose_name='工作结束时间')
    user = models.ForeignKey(User, on_delete=PROTECT, verbose_name='用户id')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_user_work_exp'
        verbose_name = '用户工作经历表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.id


class ProjectExp(models.Model):
    """项目经验"""

    pro_name = models.CharField(max_length=16, verbose_name='项目名称')
    post_name = models.CharField(max_length=16, verbose_name='职务名称')
    start_time = models.CharField(max_length=16, verbose_name='项目起始时间')
    end_time = models.CharField(max_length=16, verbose_name='项目结束时间')
    content = models.CharField(max_length=500, verbose_name='项目描述')
    user = models.ForeignKey(User, on_delete=PROTECT, verbose_name='用户id')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_user_pro_exp'
        verbose_name = '用户项目经验表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.id


class EduBkGround(models.Model):
    """教育背景"""
    school_name = models.CharField(max_length=16, verbose_name='学校名称')
    education = models.CharField(max_length=10, verbose_name='学历')
    major = models.CharField(max_length=16, verbose_name='专业')
    start_time = models.CharField(max_length=16, verbose_name='学业起始时间')
    end_time = models.CharField(max_length=16, verbose_name='学业结束时间')
    user = models.ForeignKey(User, on_delete=PROTECT, verbose_name='用户id')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_user_edu_bk'
        verbose_name = '用户教育背景表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.id


class SelfDesc(models.Model):
    """自我描述"""
    content = models.CharField(max_length=500, verbose_name='描述内容')
    user = models.ForeignKey(User, on_delete=PROTECT, verbose_name='用户id')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_user_self_desc'
        verbose_name = '用户自我描述表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.id


class ProductionShow(models.Model):
    """作品展示"""

    production_url = models.CharField(max_length=200, verbose_name='作品链接')
    explain = models.CharField(max_length=500, verbose_name='作品说明')
    user = models.ForeignKey(User, on_delete=PROTECT, verbose_name='用户id')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_user_product_show'
        verbose_name = '用户作品展示表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.id


class UserResume(models.Model):
    """个人简历表"""

    title = models.CharField(max_length=10, verbose_name='简历标题')
    user_basic = models.ForeignKey(UserBaseInfo, on_delete=CASCADE, verbose_name='用户基本信息')
    expect_work = models.ForeignKey(ExpectWork, on_delete=CASCADE, verbose_name='用户期待工作')
    work_exp = models.ForeignKey(WorkExp, on_delete=CASCADE, verbose_name='用户工作经历')
    projectexp = models.ForeignKey(ProjectExp, on_delete=CASCADE, verbose_name='用户项目经验')
    edubk = models.ForeignKey(EduBkGround, on_delete=CASCADE, verbose_name='用户教育背景')
    selfdesc = models.ForeignKey(SelfDesc, on_delete=CASCADE, verbose_name='用户自我介绍')
    worksshow = models.ForeignKey(ProductionShow, on_delete=CASCADE, verbose_name='用户作品展示')
    user = models.ForeignKey(User, on_delete=PROTECT, verbose_name='用户')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_user_resume'
        verbose_name = '用户简历表'
        verbose_name_plural = verbose_name

    def __str__(self):
        """打印对象时直接打印用户名"""
        return self.title
